package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.ExamineHistory;
import java.util.List;

public class ExaminHistoryAdapter extends ArrayAdapter<ExamineHistory> {

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2015-05-26 16:03:12 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final LinearLayout rootView;
    public final TextView mTvStatus;
    public final TextView mTvSubject;
    public final TextView mTvName;
    public final TextView mTvType;
    public final TextView mTvIsdone;
    public final TextView mTvTime;

    private ViewHolder(LinearLayout rootView, TextView mTvStatus, TextView mTvTitle,
        TextView mTvName, TextView mTvType, TextView mTvIsdone, TextView mTvTime) {
      this.rootView = rootView;
      this.mTvStatus = mTvStatus;
      this.mTvSubject = mTvTitle;
      this.mTvName = mTvName;
      this.mTvType = mTvType;
      this.mTvIsdone = mTvIsdone;
      this.mTvTime = mTvTime;
    }

    public static ViewHolder create(LinearLayout rootView) {
      TextView mTvStatus = (TextView) rootView.findViewById(R.id.listview_item_tv_status);
      TextView mTvTitle = (TextView) rootView.findViewById(R.id.tv_title_taskAdapter);
      TextView mTvName = (TextView) rootView.findViewById(R.id.listview_item_tv_name);
      TextView mTvType = (TextView) rootView.findViewById(R.id.tv_type_taskAdapter);
      TextView mTvIsdone = (TextView) rootView.findViewById(R.id.listview_item_tv_isdone);
      TextView mTvTime = (TextView) rootView.findViewById(R.id.listview_item_tv_time);
      return new ViewHolder(rootView, mTvStatus, mTvTitle, mTvName, mTvType, mTvIsdone, mTvTime);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_task, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    ExamineHistory item = getItem(position);

    vh.mTvSubject.setText(item.getTaskName() + "：" + item.getTaskValue());
    vh.mTvName.setText(item.getExeName() + "： " + item.getExeValue());
    vh.mTvType.setText(item.getOptionName() + "：" + item.getOptionValue());
    vh.mTvType.setSingleLine(false);
    vh.mTvIsdone.setText(item.getStateFullName() + "：" + item.getStateValue());
    vh.mTvIsdone.setTextColor(mContext.getResources().getColor(R.color.red));
    vh.mTvTime.setText(item.getBeginTimeName() + "：" + item.getBeginTimeValue());
    vh.mTvStatus.setVisibility(View.GONE);
    return vh.rootView;
  }

  private LayoutInflater mInflater;
  private Context mContext;

  // Constructors
  public ExaminHistoryAdapter(Context context, List<ExamineHistory> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
    this.mContext = context;
  }

  public ExaminHistoryAdapter(Context context, ExamineHistory[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }
}

